<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('评分详情')" />
    <th:block th:include="include :: summernote-css" />
    <th:block th:include="include :: select2-css" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-score-add">
        <input name="id" th:if="${grading!=null}" th:field="*{grading.id}" type="hidden">
        <input name="id" th:if="${score!=null}" th:field="*{score.id}" type="hidden">
        <div class="form-group" th:if="${grading!=null}">
            <label class="col-sm-3 control-label">评分标准：</label>
            <div class="col-sm-9">
                <input type="hidden" class="form-control" name="grading" th:field="*{grading.grading}">
                <div class="summernote" id="grading"></div>
            </div>
        </div>
        <div class="form-group" th:if="${grading!=null}">
            <label class="col-sm-3 control-label">任务阶段成果：</label>
            <div class="col-sm-9">
                <input type="hidden" class="form-control" name="stageResult" th:field="*{grading.stageResult}">
                <div class="summernote" id="stageResult"></div>
            </div>
        </div>


        <div class="form-group" th:if="${score!=null}">
            <label class="col-sm-3 control-label">评分标准：</label>
            <div class="col-sm-9">
                <div th:utext="${score.grading}"></div>
            </div>
        </div>
        <div class="form-group" th:if="${score!=null}">
            <label class="col-sm-3 control-label">任务阶段成果：</label>
            <div class="col-sm-9">
                <div th:utext="${score.stageResult}"></div>
            </div>
        </div>
        <div class="form-group" th:if="${score!=null}">
            <label class="col-sm-3 control-label">分数</label>
            <div class="col-sm-9">
                <select class="form-control" th:field="*{score.score}" name="score">
                    <option value="10">10</option>
                    <option value="9">9</option>
                    <option value="8">8</option>
                    <option value="7">7</option>
                    <option value="6">6</option>
                    <option value="5">5</option>
                    <option value="4">4</option>
                    <option value="3">3</option>
                    <option value="2">2</option>
                    <option value="1">1</option>
                </select>
            </div>
        </div>

        <div class="form-group" th:if="${score!=null}">
            <label class="col-sm-3 control-label">评语：</label>
            <div class="col-sm-9">
                <textarea type="text" name="comments" th:field="*{score.comments}" class="form-control" placeholder="请输入评语"></textarea>
            </div>
        </div>
        <div class="form-group" th:if="${score!=null}">
            <div class="col-sm-12 col-sm-offset-3">
                <button type="button" class="btn btn-primary" onclick="submitHandler('score')">提交</button>
                <button onclick="$.modal.close()" class="btn btn-danger" type="button">关闭</button>
            </div>
        </div>
        <div class="form-group" th:if="${grading!=null}">
            <div class="col-sm-12 col-sm-offset-3">
                <button type="button" class="btn btn-primary" onclick="submitHandler('grading')">提交</button>
                <button onclick="$.modal.close()" class="btn btn-danger" type="button">关闭</button>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: summernote-js" />
<th:block th:include="include :: select2-js" />
<script th:inline="javascript">
    var prefix = ctx + "taskcenter/score"

    $(function() {
        $('.summernote').each(function(i) {
            $('#' + this.id).summernote({
                lang: 'zh-CN',
                dialogsInBody: true,
                callbacks: {
                    onChange: function(contents, $edittable) {
                        $("input[name='" + this.id + "']").val(contents);
                    },
                    onImageUpload: function(files) {
                        var obj = this;
                        var data = new FormData();
                        data.append("file", files[0]);
                        $.ajax({
                            type: "post",
                            url: ctx + "common/upload",
                            data: data,
                            cache: false,
                            contentType: false,
                            processData: false,
                            dataType: 'json',
                            success: function(result) {
                                if (result.code == web_status.SUCCESS) {
                                    $('#' + obj.id).summernote('insertImage', result.url);
                                } else {
                                    $.modal.alertError(result.msg);
                                }
                            },
                            error: function(error) {
                                $.modal.alertWarning("图片上传失败。");
                            }
                        });
                    }
                }
            });
            var content = $("input[name='" + this.id + "']").val();
            $('#' + this.id).summernote('code', content);
        })
    });

    function submitHandler(type) {
        if ($.validate.form()) {
            var url= prefix+"/edit/"+type
            var data = $('#form-score-add').serialize();
            var config = {
                url: url,
                type: "post",
                dataType: "json",
                data: data,
                beforeSend: function () {
                    $.modal.loading("正在处理中，请稍候...");
                },
                success: function(result) {
                    if (typeof callback == "function") {
                        callback(result);
                    }
                    //关闭遮罩层
                    $.modal.closeLoading();
                    //$.operate.successTabCallback(result);
                }
            };
            $.ajax(config)
        }
    }
</script>
</body>
</html>